﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CenterDateAchieve.Forms;
using CenterDateAchieve.Helper;
using AppToolKit.Core.Context.Spring;
using BLL.Business;
using BLL.Action.Job;

namespace CenterDateAchieve
{
    public partial class HandTransferForm : FormBase,IAutoWiring
    {
        public HandTransferForm()
        {
            InitializeComponent();
        }
        private const string Code = "code";
        private const string Descript = "descript";
        [AutoWiring]
        public JobFaced JobFacedHolder { get; set; }
        [AutoWiring]
        public TaskFaced TaskFacedHolder { get; set; }

        private void HandTransferForm_Load(object sender, EventArgs e)
        {
            try
            {
                TreeViewHelper.BulidTreeView(treeHotel, "酒店", TaskFacedHolder.GetHotelAll(), null);

                ckbTask.DataSource = TaskFacedHolder.GetTaskAll(string.Empty,string.Empty).Tables[0];
                ckbTask.ValueMember = Code;
                ckbTask.DisplayMember = Descript;
            }
            catch (Exception ex){
                MessageBox.Show(ex.Message);
            }
        }

        private void treeHotel_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Action != TreeViewAction.Unknown)
            {
                TreeViewHelper.NodeChecked(e.Node);
            }
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btDownLoad_Click(object sender, EventArgs e)
        {
           List<string> nodes=TreeViewHelper.GetCheckedNodes(treeHotel.Nodes[0]);
          
           JobFacedHolder.ManualRun(nodes, GetTasks());



        }
        private List<string> GetTasks()
        {
            List<string> task = new List<string>();
            int length=ckbTask.Items.Count;
            for (int i = 0; i < length; i++)
            {
                if (ckbTask.GetItemChecked(i))
                {
                    DataRowView view = ckbTask.Items[i] as DataRowView;
                   task.Add( Convert.ToString(view.Row[Code]));
                    
                }
            }
           return task;
        }
        
    }
}
